package com.topgay.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.topgay.service.CSCenterService;

@Controller
@RequestMapping("/cscenter/")
public class CSCenterController {

	@Autowired
	private CSCenterService cscenterService;
	
	/**
	 * 공지사항
	 * @param page
	 * @param model
	 * @throws Exception
	 */
	@RequestMapping("/notice.do")
	public String noticePage(@RequestParam(defaultValue="1")String page, ModelMap model) throws Exception{
		
		int pageNo = 1;
		try {
			pageNo = Integer.parseInt(page);
		}catch(Exception e){
			pageNo = 1;
		}
		return cscenterList(pageNo, 5, model, "cscenter/notice");
	}
	
	/**
	 * FAQ
	 * @return
	 */
	@RequestMapping("/faq.do")
	public String faqPage(@RequestParam(defaultValue="1")String page, ModelMap model) throws Exception{
		int pageNo = 1;
		try {
			pageNo = Integer.parseInt(page);
		}catch(Exception e){
			pageNo = 1;
		}
		return cscenterList(pageNo, 6, model, "cscenter/faq");
	}
	
	//1:1문의
	@RequestMapping("/qna.do")
	public String qnaPage(){
		return "cscenter/qna";
	}
	
//	/신고하기
	@RequestMapping("/declare.do")
	public String declarePage(){
		return "cscenter/declare";
	}
	

	/**
	 * Notice, FAQ 목록 조회
	 * @param page
	 * @param divide - 5:Notice, 6:FAQ
	 * @param model
	 * @param url
	 * @return
	 * @throws Exception
	 */
	public String cscenterList(int page, int divide, ModelMap model, String url) throws Exception{
		Map map = cscenterService.getCSCenterList(page, divide);
		model.addAllAttributes(map);
		return url;
	}
	
	
	
}
